package cn.ailanyin.home.module.things.controller;

import cn.ailanyin.home.common.entity.PageQuery;
import cn.ailanyin.home.common.entity.PageResult;
import cn.ailanyin.home.common.entity.Result;
import cn.ailanyin.home.module.cupboard.dto.CupboardDTO;
import cn.ailanyin.home.module.cupboard.vo.CupboardVO;
import cn.ailanyin.home.module.things.dto.ThingsDTO;
import cn.ailanyin.home.module.things.service.IThingsService;
import cn.ailanyin.home.module.things.vo.ThingsVO;
import com.github.pagehelper.PageHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 小怪兽
 * @version 1.0
 * @date 2024/4/13 0013 20:30:59
 */
@Validated
@RestController
@RequiredArgsConstructor
@Tag(name = "物品管理")
@RequestMapping("/things")
public class ThingsController {

    /**
     * 事物服务
     */
    private final IThingsService thingsService;

    /**
     * 分页查询
     *
     * @param dto       dto
     * @param pageQuery 页面查询
     * @return {@link Result}<{@link String}>
     */
    @GetMapping("/list")
    @Operation(summary = "分页查询")
    public PageResult<ThingsVO> list(ThingsDTO dto, @ParameterObject PageQuery pageQuery) {
        PageHelper.startPage(pageQuery.getPageNum(), pageQuery.getPageSize());
        return PageResult.build(thingsService.list(dto));
    }

    /**
     * 新增/编辑
     *
     * @param dto dto
     * @return {@link Result}<{@link Void}>
     */
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "新增/修改物品")
    public Result<Void> saveOrUpdate(@RequestBody ThingsDTO dto) {
        thingsService.saveOrUpdate(dto);
        return Result.success();
    }

    /**
     * 删除
     *
     * @param id id
     * @return {@link Result}<{@link Void}>
     */
    @PostMapping("/delete")
    @Operation(summary = "删除物品")
    public Result<Void> delete(String id) {
        thingsService.delete(id);
        return Result.success();
    }

}
